package gq.example.config;

import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
import gq.example.json.FastjsonConfigurator;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;

@Configuration
@Slf4j
public class WebMvcConfiguration implements WebMvcConfigurer {

    /**
     * swagger配置
     * @param environment
     * @return
     */
    @Bean
    public OpenAPI publicApi(Environment environment) {
        return new OpenAPI()
                .info(new Info()
                        .title("反馈系统接口文档")
                        .description("")
                        .version("1.0")
                );
    }


    @Override
    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        FastjsonConfigurator.init();
        // 创建 Fastjson2 的消息转换器
        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();

        converters.add(0, converter); // 放在首位优先使用

        log.info("初始化Fastjson2");
    }


}
